summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-as/llvm-as.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2018-06-26 13:56:49 +0000
committerTeresa Johnson <tejohnson@google.com>2018-06-26 13:56:49 +0000
commit63ee0e73e44e80d4e6d388de734cdb5106c8a6de (patch)
tree84f4df06ba721af4966e6f527e22e8bf9d094068 /llvm/tools/llvm-as/llvm-as.cpp
parent5915777eca88a8c14c58869219aa6fe1543a70b5 (diff)
downloadbcm5719-llvm-63ee0e73e44e80d4e6d388de734cdb5106c8a6de.tar.gz
bcm5719-llvm-63ee0e73e44e80d4e6d388de734cdb5106c8a6de.zip
[ThinLTO] Parse module summary index from assembly
Summary: Adds assembly parsing support for the module summary index (follow on to r333335 which added the assembly writing support). I added support to llvm-as to invoke the index parsing, so that it can create either a bitcode file with a Module and a per-module index, or a combined index without a Module. I will send follow on patches soon to do the following: - add support to tools such as llvm-lto2 to parse the per-module indexes from assembly instead of bitcode when testing the thin link. - verification support. Depends on D47844 and D47842. Reviewers: pcc, dexonsmith, mehdi_amini Subscribers: inglorion, eraman, steven_wu, llvm-commits Differential Revision: https://reviews.llvm.org/D47905 llvm-svn: 335602
Diffstat (limited to 'llvm/tools/llvm-as/llvm-as.cpp')
-rw-r--r--llvm/tools/llvm-as/llvm-as.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
index 258f5141e11..bb4233aa9ba 100644
--- a/llvm/tools/llvm-as/llvm-as.cpp
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -19,6 +19,7 @@
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
@@ -63,7 +64,7 @@ static cl::opt<std::string> ClDataLayout("data-layout",
cl::value_desc("layout-string"),
cl::init(""));
-static void WriteOutputFile(const Module *M) {
+static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) {
// Infer the output filename if needed.
if (OutputFilename.empty()) {
if (InputFilename == "-") {
@@ -83,9 +84,24 @@ static void WriteOutputFile(const Module *M) {
exit(1);
}
- if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
- WriteBitcodeToFile(*M, Out->os(), PreserveBitcodeUseListOrder, nullptr,
- EmitModuleHash);
+ if (Force || !CheckBitcodeOutputToConsole(Out->os(), true)) {
+ const ModuleSummaryIndex *IndexToWrite = nullptr;
+ // Don't attempt to write a summary index unless it contains any entries.
+ // Otherwise we get an empty summary section.
+ if (Index && Index->begin() != Index->end())
+ IndexToWrite = Index;
+ if (!IndexToWrite || (M && (!M->empty() || !M->global_empty())))
+ // If we have a non-empty Module, then we write the Module plus
+ // any non-null Index along with it as a per-module Index.
+ // If both are empty, this will give an empty module block, which is
+ // the expected behavior.
+ WriteBitcodeToFile(*M, Out->os(), PreserveBitcodeUseListOrder,
+ IndexToWrite, EmitModuleHash);
+ else
+ // Otherwise, with an empty Module but non-empty Index, we write a
+ // combined index.
+ WriteIndexToFile(*IndexToWrite, Out->os());
+ }
// Declare success.
Out->keep();
@@ -98,12 +114,14 @@ int main(int argc, char **argv) {
// Parse the file now...
SMDiagnostic Err;
- std::unique_ptr<Module> M = parseAssemblyFile(
+ auto ModuleAndIndex = parseAssemblyFileWithIndex(
InputFilename, Err, Context, nullptr, !DisableVerify, ClDataLayout);
+ std::unique_ptr<Module> M = std::move(ModuleAndIndex.Mod);
if (!M.get()) {
Err.print(argv[0], errs());
return 1;
}
+ std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);
if (!DisableVerify) {
std::string ErrorStr;
@@ -114,13 +132,17 @@ int main(int argc, char **argv) {
errs() << OS.str();
return 1;
}
+ // TODO: Implement and call summary index verifier.
}
- if (DumpAsm)
+ if (DumpAsm) {
errs() << "Here's the assembly:\n" << *M.get();
+ if (Index.get() && Index->begin() != Index->end())
+ Index->print(errs());
+ }
if (!DisableOutput)
- WriteOutputFile(M.get());
+ WriteOutputFile(M.get(), Index.get());
return 0;
}
OpenPOWER on IntegriCloud