diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /tools/llvm-as/llvm-as.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'tools/llvm-as/llvm-as.cpp')
-rw-r--r-- | tools/llvm-as/llvm-as.cpp | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 9f0f162b74f8..bb4233aa9ba0 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -19,12 +19,12 @@ #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" +#include "llvm/Support/InitLLVM.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/Signals.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" @@ -59,7 +59,12 @@ static cl::opt<bool> PreserveBitcodeUseListOrder( cl::desc("Preserve use-list order when writing LLVM bitcode."), cl::init(true), cl::Hidden); -static void WriteOutputFile(const Module *M) { +static cl::opt<std::string> ClDataLayout("data-layout", + cl::desc("data layout string to use"), + cl::value_desc("layout-string"), + cl::init("")); + +static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) { // Infer the output filename if needed. if (OutputFilename.empty()) { if (InputFilename == "-") { @@ -79,30 +84,44 @@ 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(); } int main(int argc, char **argv) { - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(argv[0]); - PrettyStackTraceProgram X(argc, argv); + InitLLVM X(argc, argv); LLVMContext Context; - llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); // Parse the file now... SMDiagnostic Err; - std::unique_ptr<Module> M = - parseAssemblyFile(InputFilename, Err, Context, nullptr, !DisableVerify); + 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; @@ -113,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; } |